package com.aponteitor.desktop.event;

import com.aponteitor.desktop.Program;

/**
 * @author wellsantos@wellsantos.com
 */
public class TimerActionHandler extends ActionHandler {

    private Runnable runnable;
    private long delay; 
    
    public TimerActionHandler(Runnable runnable) {
        this(runnable, 0);
    }
    
    public TimerActionHandler(Runnable runnable, long delay) {
        setup(runnable, delay);
    }
    
    public TimerActionHandler(Boolean doubleClick, Runnable runnable, long delay) {
        super(doubleClick);
        setup(runnable, delay);
    }

    public TimerActionHandler(int keyCode, Runnable runnable, long delay) {
        super(keyCode);
        setup(runnable, delay);
    }
    
    private void setup(Runnable runnable, long delay) {
        if (runnable == null){
            throw new IllegalArgumentException("runnable must be != null");
        }
        this.runnable = runnable;
        this.delay = delay;
    }

    @Override
    public void run() {
        Program.schedule(runnable, delay);
    }

}
